﻿using System.Reflection;

namespace Borg
{
    internal class DeregisterFromSlotsTask : Task<ExtensionInfo>
    {
        private readonly ExtensionTypeInfo _eti;

        public DeregisterFromSlotsTask(ExtensionInfo obj, ExtensionTypeInfo eti,
            uint taskGroupId, Assembly initiator)
            : base(obj, taskGroupId, initiator)
        {
            _eti = eti;
        }

        public override void Execute()
        {
            if (_eti == null)
                obj.InternalDeregisterFromSlots(initiator, false);
            else
                obj.InternalDeregisterFromSlots(_eti, initiator, false);
        }

        public override string ToString()
        {
            return _eti == null
                ? string.Format("{0}: {1}.InternalDeregisterFromSlots()", taskGroupId, obj)
                : string.Format("{0}: {1}.InternalDeregisterFromSlots({2})", taskGroupId, obj, _eti);
        }

        public override string Name
        {
            get
            {
                return _eti == null
                    ? string.Format("DeregisterFromSlots({0})", obj.Name)
                    : string.Format("DeregisterFromSlots({0}, {1})", obj.Name, _eti.Name);
            }
        }
    }
}

